package com.pacs.control;

import com.jfinal.core.Controller;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.pacs.jfinal.weixin.api.QrcodeApi;
import com.pacs.model.Reports;
import com.pacs.tools.LogUtil;

public class WeixinQRCodeController extends Controller {
	public void index(){
		String rid = this.getPara("reportid");
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(this.getPara("reportid").getClass()).append("  ").append(rid).append("  ").append(this.getPara("reportid"));
		LogUtil.debug(stringBuilder.toString());
		Reports reports = Reports.dao.findById(Long.valueOf(rid));
		if (rid == null || reports == null) {
			renderNull();
			return;
		}
		if (reports.getQrCode() == null || reports.getQrCode().isEmpty()) {			
			ApiResult qrresult = QrcodeApi.createTemporary(2592000, "ReportQR_" + rid);
			reports.setQrCode(qrresult.toString());
			reports.update();
			this.renderJson(qrresult);
		}else {
			ApiResult qrresult = new ApiResult(reports.getQrCode());
			this.renderJson(qrresult);
		}
	}
}
